import { customerHttp, fullHttp } from '@/utils/http'

export function login(data: any, type: string) {
  return customerHttp.request({
    url: '/auth/oauth/token',
    method: 'post',
    params: {
      randomStr: 'blockPuzzle',
      grant_type: 'password',
      identity: type
    },
    data
  })
}

export function loginByCode(
  mobile: string,
  code: string,
  identity: string,
  equipment: string
) {
  return customerHttp.request({
    url: '/auth/oauth/token',
    method: 'post',
    params: {
      randomStr: 'blockPuzzle',
      grant_type: 'sms',
      mobile,
      code,
      identity,
      equipment
    }
  })
}

export function loginApplet(data: any) {
  return customerHttp.request({
    url: '/auth/oauth/token',
    method: 'post',
    params: {
      randomStr: 'blockPuzzle',
      grant_type: 'applet',
      ...data
    },
    data
  })
}

/**
 *  个人中心数据获取
 *
 * @param data
 * @returns
 */
export function getUserInfo() {
  return customerHttp.request({
    url: '/admin/user/info',
    method: 'get'
  })
}

/**
 *  解密
 *
 * @param params
 * @returns
 */
export function sessionKeyApi(params: any) {
  return fullHttp.request({
    url: 'https://api.weixin.qq.com/sns/jscode2session',
    method: 'get',
    params
  })
}

// 绑定appid
export function bindAppIdApi(data: any) {
  return customerHttp.request({
    url: '/auth/token/user/bind/app-id',
    method: 'post',
    data
  })
}
/**
 *  通过手机号查询所有绑定的租户信息
 * https://yapi.ops.yunlizhi.cn/project/907/interface/api/59441
 * @param data
 * @returns
 */
export function getTenantsByPhone(data: any) {
  return customerHttp.request({
    url: '/admin/user/query_tenants_by_phone',
    method: 'post',
    data
  })
}
/**
 *  小程序租户切换
 * https://yapi.ops.yunlizhi.cn/project/907/interface/api/60511
 * @param data
 * @returns
 */
export function miniTenantChange(userName: string, equipment: string) {
  return customerHttp.request({
    url: `/auth/token/mini_tenant_change?userName=${userName}&clientId=cHVyY2hhc2VfbWluaTpwdXJjaGFzZV9taW5p&equipment=${equipment}`,
    method: 'post'
  })
}

/**
 * FA
 * https://yapi.ops.yunlizhi.cn/project/907/interface/api/59441
 */
export const sendVerifyCode = (data: any) =>
  customerHttp.request({
    url: '/reach/sms/sendVerifyCode',
    method: 'post',
    data
  })

/**
 * 查询是否绑定了小程序
 * https://yapi.ops.yunlizhi.cn/project/907/interface/api/64231
 */
export const vaildBindPhoneApi = (data: any) =>
  customerHttp.request({
    url: '/admin/user/query-mini-bind-status',
    method: 'post',
    data
  })
